import 'package:finance_app/src/entities/product_entity.dart';
import 'package:finance_app/src/entities/ocr_attachment_entity.dart';
import 'package:finance_app/src/page/dashboard/amount_gst/amount_gst_rate_category_page.dart';

productEntityFromJson(ProductEntity data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['categories'] != null) {
		data.categories = (json['categories'] as List).map((v) => v.toString()).toList().cast<String>();
	}
	if (json['category'] != null) {
		data.category = json['category'];
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['code'] != null) {
		data.code = json['code'].toString();
	}
	if (json['barcode'] != null) {
		data.barcode = json['barcode'];
	}
	if (json['unit_type'] != null) {
		data.unitType = json['unit_type'].toString();
	}
	if (json['description'] != null) {
		data.description = json['description'];
	}
	if (json['enable_sell'] != null) {
		data.enableSell = json['enable_sell'] is String
				? int.tryParse(json['enable_sell'])
				: json['enable_sell'].toInt();
	}
	if (json['currency_code'] != null) {
		data.currencyCode = json['currency_code'].toString();
	}
	if (json['price'] != null) {
		data.price = json['price'] is String
				? num.tryParse(json['price'])
				: json['price'];
	}
	if (json['tax_id'] != null) {
		data.taxId = json['tax_id'] is String
				? int.tryParse(json['tax_id'])
				: json['tax_id'].toInt();
	}
	if (json['tax'] != null) {
		data.tax = SettingDataTax().fromJson(json['tax']);
	}
	if (json['is_tax_inclusive'] != null) {
		data.isTaxInclusive = json['is_tax_inclusive'] is String
				? int.tryParse(json['is_tax_inclusive'])
				: json['is_tax_inclusive'].toInt();
	}
	if (json['enable_purchase'] != null) {
		data.enablePurchase = json['enable_purchase'] is String
				? int.tryParse(json['enable_purchase'])
				: json['enable_purchase'].toInt();
	}
	if (json['purchase_currency_code'] != null) {
		data.purchaseCurrencyCode = json['purchase_currency_code'].toString();
	}
	if (json['purchase_price'] != null) {
		data.purchasePrice = json['purchase_price'] is String
				? num.tryParse(json['purchase_price'])
				: json['purchase_price'];
	}
	if (json['purchase_tax_id'] != null) {
		data.purchaseTaxId = json['purchase_tax_id'] is String
				? int.tryParse(json['purchase_tax_id'])
				: json['purchase_tax_id'].toInt();
	}
	if (json['purchase_tax'] != null) {
		data.purchaseTax = SettingDataTax().fromJson(json['purchase_tax']);
	}
	if (json['purchase_is_tax_inclusive'] != null) {
		data.purchaseIsTaxInclusive = json['purchase_is_tax_inclusive'] is String
				? int.tryParse(json['purchase_is_tax_inclusive'])
				: json['purchase_is_tax_inclusive'].toInt();
	}
	if (json['enable_inventory'] != null) {
		data.enableInventory = json['enable_inventory'] is String
				? int.tryParse(json['enable_inventory'])
				: json['enable_inventory'].toInt();
	}
	if (json['inventory_left'] != null) {
		data.inventoryLeft = json['inventory_left'] is String
				? int.tryParse(json['inventory_left'])
				: json['inventory_left'].toInt();
	}
	if (json['has_inventory'] != null) {
		data.hasInventory = json['has_inventory'] is String
				? int.tryParse(json['has_inventory'])
				: json['has_inventory'].toInt();
	}
	if (json['has_bom'] != null) {
		data.hasBom = json['has_bom'] is String
				? int.tryParse(json['has_bom'])
				: json['has_bom'].toInt();
	}
	if (json['boms'] != null) {
		data.boms = (json['boms'] as List).map((v) => ProductBoms().fromJson(v)).toList();
	}
	if (json['is_activated'] != null) {
		data.isActivated = json['is_activated'] is String
				? int.tryParse(json['is_activated'])
				: json['is_activated'].toInt();
	}
	if (json['enabled'] != null) {
		data.enabled = json['enabled'] is String
				? int.tryParse(json['enabled'])
				: json['enabled'].toInt();
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	if (json['attachments'] != null) {
		data.attachments = (json['attachments'] as List).map((v) => OcrAttachmentEntity().fromJson(v)).toList();
	}
	if (json['unit_type_text'] != null) {
		data.unitTypeText = json['unit_type_text'].toString();
	}
	if (json['discount_type'] != null) {
		data.discountType = json['discount_type'].toString();
	}
	if (json['discount_value'] != null) {
		data.discountValue = json['discount_value'] is String
				? num.tryParse(json['discount_value'])
				: json['discount_value'];
	}
	return data;
}

Map<String, dynamic> productEntityToJson(ProductEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['categories'] = entity.categories;
	data['category'] = entity.category;
	data['name'] = entity.name;
	data['code'] = entity.code;
	data['barcode'] = entity.barcode;
	data['unit_type'] = entity.unitType;
	data['description'] = entity.description;
	data['enable_sell'] = entity.enableSell;
	data['currency_code'] = entity.currencyCode;
	data['price'] = entity.price;
	data['tax_id'] = entity.taxId;
	data['tax'] = entity.tax?.toJson();
	data['is_tax_inclusive'] = entity.isTaxInclusive;
	data['enable_purchase'] = entity.enablePurchase;
	data['purchase_currency_code'] = entity.purchaseCurrencyCode;
	data['purchase_price'] = entity.purchasePrice;
	data['purchase_tax_id'] = entity.purchaseTaxId;
	data['purchase_tax'] = entity.purchaseTax?.toJson();
	data['purchase_is_tax_inclusive'] = entity.purchaseIsTaxInclusive;
	data['enable_inventory'] = entity.enableInventory;
	data['inventory_left'] = entity.inventoryLeft;
	data['has_inventory'] = entity.hasInventory;
	data['has_bom'] = entity.hasBom;
	data['boms'] =  entity.boms?.map((v) => v.toJson())?.toList();
	data['is_activated'] = entity.isActivated;
	data['enabled'] = entity.enabled;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	data['attachments'] =  entity.attachments?.map((v) => v.toJson())?.toList();
	data['unit_type_text'] = entity.unitTypeText;
	data['discount_type'] = entity.discountType;
	data['discount_value'] = entity.discountValue;
	return data;
}

productBomsFromJson(ProductBoms data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['categories'] != null) {
		data.categories = (json['categories'] as List).map((v) => v.toString()).toList().cast<String>();
	}
	if (json['code'] != null) {
		data.code = json['code'].toString();
	}
	if (json['barcode'] != null) {
		data.barcode = json['barcode'];
	}
	if (json['unit_type'] != null) {
		data.unitType = json['unit_type'].toString();
	}
	if (json['description'] != null) {
		data.description = json['description'].toString();
	}
	if (json['enable_sell'] != null) {
		data.enableSell = json['enable_sell'] is String
				? int.tryParse(json['enable_sell'])
				: json['enable_sell'].toInt();
	}
	if (json['currency_code'] != null) {
		data.currencyCode = json['currency_code'].toString();
	}
	if (json['price'] != null) {
		data.price = json['price'] is String
				? num.tryParse(json['price'])
				: json['price'];
	}
	if (json['tax_id'] != null) {
		data.taxId = json['tax_id'] is String
				? int.tryParse(json['tax_id'])
				: json['tax_id'].toInt();
	}
	if (json['is_tax_inclusive'] != null) {
		data.isTaxInclusive = json['is_tax_inclusive'] is String
				? int.tryParse(json['is_tax_inclusive'])
				: json['is_tax_inclusive'].toInt();
	}
	if (json['enable_purchase'] != null) {
		data.enablePurchase = json['enable_purchase'] is String
				? int.tryParse(json['enable_purchase'])
				: json['enable_purchase'].toInt();
	}
	if (json['purchase_currency_code'] != null) {
		data.purchaseCurrencyCode = json['purchase_currency_code'].toString();
	}
	if (json['purchase_price'] != null) {
		data.purchasePrice = json['purchase_price'] is String
				? num.tryParse(json['purchase_price'])
				: json['purchase_price'];
	}
	if (json['purchase_tax_id'] != null) {
		data.purchaseTaxId = json['purchase_tax_id'] is String
				? int.tryParse(json['purchase_tax_id'])
				: json['purchase_tax_id'].toInt();
	}
	if (json['purchase_is_tax_inclusive'] != null) {
		data.purchaseIsTaxInclusive = json['purchase_is_tax_inclusive'] is String
				? int.tryParse(json['purchase_is_tax_inclusive'])
				: json['purchase_is_tax_inclusive'].toInt();
	}
	if (json['enable_inventory'] != null) {
		data.enableInventory = json['enable_inventory'] is String
				? int.tryParse(json['enable_inventory'])
				: json['enable_inventory'].toInt();
	}
	if (json['inventory_left'] != null) {
		data.inventoryLeft = json['inventory_left'] is String
				? int.tryParse(json['inventory_left'])
				: json['inventory_left'].toInt();
	}
	if (json['has_bom'] != null) {
		data.hasBom = json['has_bom'] is String
				? int.tryParse(json['has_bom'])
				: json['has_bom'].toInt();
	}
	if (json['is_activated'] != null) {
		data.isActivated = json['is_activated'] is String
				? int.tryParse(json['is_activated'])
				: json['is_activated'].toInt();
	}
	if (json['enabled'] != null) {
		data.enabled = json['enabled'] is String
				? int.tryParse(json['enabled'])
				: json['enabled'].toInt();
	}
	if (json['created_by'] != null) {
		data.createdBy = json['created_by'];
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	if (json['deleted_at'] != null) {
		data.deletedAt = json['deleted_at'];
	}
	if (json['pivot'] != null) {
		data.pivot = ProductBomsPivot().fromJson(json['pivot']);
	}
	if (json['unit_type_text'] != null) {
		data.unitTypeText = json['unit_type_text'].toString();
	}
	return data;
}

Map<String, dynamic> productBomsToJson(ProductBoms entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['name'] = entity.name;
	data['categories'] = entity.categories;
	data['code'] = entity.code;
	data['barcode'] = entity.barcode;
	data['unit_type'] = entity.unitType;
	data['description'] = entity.description;
	data['enable_sell'] = entity.enableSell;
	data['currency_code'] = entity.currencyCode;
	data['price'] = entity.price;
	data['tax_id'] = entity.taxId;
	data['is_tax_inclusive'] = entity.isTaxInclusive;
	data['enable_purchase'] = entity.enablePurchase;
	data['purchase_currency_code'] = entity.purchaseCurrencyCode;
	data['purchase_price'] = entity.purchasePrice;
	data['purchase_tax_id'] = entity.purchaseTaxId;
	data['purchase_is_tax_inclusive'] = entity.purchaseIsTaxInclusive;
	data['enable_inventory'] = entity.enableInventory;
	data['inventory_left'] = entity.inventoryLeft;
	data['has_bom'] = entity.hasBom;
	data['is_activated'] = entity.isActivated;
	data['enabled'] = entity.enabled;
	data['created_by'] = entity.createdBy;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	data['deleted_at'] = entity.deletedAt;
	data['pivot'] = entity.pivot?.toJson();
	data['unit_type_text'] = entity.unitTypeText;
	return data;
}

productBomsPivotFromJson(ProductBomsPivot data, Map<String, dynamic> json) {
	if (json['product_id'] != null) {
		data.productId = json['product_id'] is String
				? int.tryParse(json['product_id'])
				: json['product_id'].toInt();
	}
	if (json['material_id'] != null) {
		data.materialId = json['material_id'] is String
				? int.tryParse(json['material_id'])
				: json['material_id'].toInt();
	}
	if (json['quantity'] != null) {
		data.quantity = json['quantity'] is String
				? int.tryParse(json['quantity'])
				: json['quantity'].toInt();
	}
	return data;
}

Map<String, dynamic> productBomsPivotToJson(ProductBomsPivot entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['product_id'] = entity.productId;
	data['material_id'] = entity.materialId;
	data['quantity'] = entity.quantity;
	return data;
}